package wsi.task.input;

import org.rygh.core.html.table.TableTuple;
import org.rygh.semantic.gui.swing.input.Input;

import wsi.dataguide.tree.WSXmlLeaf;

public class InputLocation {

	private final WSXmlLeaf node;

	private Input input;
	private boolean exactMatch;
	private double similarity;

	public InputLocation(WSXmlLeaf node) {
		this.node = node;
	}

	public TableTuple getCells() {
		TableTuple tuple = new TableTuple();

		tuple.add(node.getValue().getName());
		tuple.add(input.getValue());
		tuple.add(exactMatch ? "exact" : "non-exact");
		tuple.add(String.format("%.2f", similarity));
		tuple.add(node.getXpath().getValue());

		return tuple;
	}

	public WSXmlLeaf getNode() {
		return node;
	}

	public double isAreAllSimilar() {
		return similarity;
	}

	public boolean isExactMatch() {
		return exactMatch;
	}

	public void setExactMatch(boolean exactMatch) {
		this.exactMatch = exactMatch;
	}

	public void setInput(Input input) {
		this.input = input;
	}

	public void setSimilarity(double areAllSimilar) {
		this.similarity = areAllSimilar;
	}

	@Override
	public String toString() {
		StringBuilder sbuilder = new StringBuilder();

		sbuilder.append(String.format("%s: input=%s node=%s %s sim=%.2f", node
				.getValue().getName(), input, node.getValue().getValue(),
				exactMatch ? "exact" : "non-exact", similarity));
		sbuilder.append("\r\n");
		sbuilder.append(node.getXpath());
		sbuilder.append("\r\n");

		return sbuilder.toString();
	}

}
